import {defineStore} from 'pinia'
import {ref, reactive, type Ref} from "vue";

export const useUserStore = defineStore(
    'useUserStore',
    () => {
        let userInfo: any = ref({
            avatar: '',
            nickName: '',
            email: '',
            gender: '',
            userName: '',
            id: '',
            signature: ''
        })

        let token: any = ref('')

        let logout = () => {
            userInfo.value = {}
            token.value = ''
            uni.removeStorageSync("useCarStore")
            uni.reLaunch({
                url: '/pages/login/login'
            })
        }

        return {
            userInfo, token, logout
        }
    },
    {
        // 配置持久化
        persist: {
            // 调整为兼容多端的API
            storage: {
                setItem(key, value) {
                    uni.setStorageSync(key, value) // [!code warning]
                },
                getItem(key) {
                    return uni.getStorageSync(key) // [!code warning]
                },
            },
        },
    }
)
